package com.lirisheng.experiment.event;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ApplicationEventMulticaster;
import org.springframework.context.event.SimpleApplicationEventMulticaster;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
public class EventConfiguration {

//    @Bean(AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME)
//    ApplicationEventMulticaster applicationEventMulticaster(ThreadPoolTaskExecutor taskExecutor){
//        SimpleApplicationEventMulticaster eventMulticaster =new SimpleApplicationEventMulticaster();
//        eventMulticaster.setTaskExecutor(taskExecutor);
//        return  eventMulticaster;
//    }

    @Bean(AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME)
    ApplicationEventMulticaster applicationEventMulticaster(@Qualifier("customPoolTask") ThreadPoolTaskExecutor taskExecutor){
        SimpleApplicationEventMulticaster eventMulticaster =new SimpleApplicationEventMulticaster();
        eventMulticaster.setTaskExecutor(taskExecutor);
        return  eventMulticaster;
    }

}
